package builderPattenr;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * @Author: 582895699@qq.com
 * @Desctription: 建造者模式
 * @Date: Created in 2021/12/14 10:00
 */
@Getter
@Setter
@ToString
public class Computer {

    private String cpu;
    private String ram;
    private Integer usbCount;
    private String keyboard;
    private String display;

    public Computer(Builder builder) {
        this.cpu = builder.cpu;
        this.ram = builder.ram;
        this.usbCount = builder.usbCount;
        this.keyboard = builder.keyboard;
        this.display = builder.display;
    }

    public static class Builder {
        private String cpu;
        private String ram;
        private Integer usbCount;
        private String keyboard;
        private String display;

        public Builder(String cpu, String ram) {
            this.cpu = cpu;
            this.ram = ram;
        }

        public Builder setUsbCount(Integer usbCount) {
            this.usbCount = usbCount;
            return this;
        }

        public Builder setKeyboard(String keyboard) {
            this.keyboard = keyboard;
            return this;
        }

        public Builder setDisplay(String display) {
            this.display = display;
            return this;
        }

        public Computer builder() {
            return new Computer(this);
        }
    }

    public static void main(String[] args) {
        Computer builder = new Builder("cpu", "ram")
                .setDisplay("123")
                .setUsbCount(13)
                .builder();
        System.out.println(builder.toString());

    }
}
